import request from '@/utils/request'

// 房间列表
export function getList(params) {
  return request({
    url: '/apartment/room/list',
    method: 'get',
    params: params
  })
}

export function getDetail(roomId) {
  return request({
    url: `/apartment/room/${roomId}`,
    method: 'get'
  })
}

export function getDeviceList(roomId) {
  return request({
    url: `/apartment/room/device-list/${roomId}`,
    method: 'get'
  })
}

// 获取未绑定门锁的房间列表
export function getNotBindLockList(params) {
  return request({
    url: `/apartment/room/not-bind-list/1`,
    method: 'get',
    params: params
  })
}

// 获取未绑定电表的房间列表
export function getNotBindMeterList(params) {
  return request({
    url: `/apartment/room/not-bind-list/2`,
    method: 'get',
    params: params
  })
}

// 编辑备注
export function editRemark(id, remark) {
  const data = {
    roomId: id,
    remark
  }

  return request({
    url: '/apartment/room',
    method: 'put',
    data: data
  })
}

// 删除房间
export function deleteRoom(roomId) {
  return request({
    url: `/apartment/room/${roomId}`,
    method: 'delete'
  })
}

// 置为脏房
export function setDirty(roomId) {
  return request({
    url: `/apartment/room/dirty/${roomId}`,
    method: 'put'
  })
}

// 置为净房 
export function setClean(roomId) {
  return request({
    url: `/apartment/room/clean/${roomId}`,
    method: 'put'
  })
}

// 获取可用房间列表（未被占用的房间）
export function listAvailableRooms(params) {
  return request({
    url: '/apartment/room/empty-list',
    method: 'get',
    params: params || {
      pageNum: 1,
      pageSize: 20  // 默认加载100个可用房间
    }
  })
}

export default {
  getList,
  getDeviceList,
  editRemark,
  getNotBindLockList,
  getDetail,
  deleteRoom,
  setDirty,
  setClean,
  listAvailableRooms
}